<script setup>
import { getOrderDetailApi } from '@/apis/order'
import { onMounted,ref } from 'vue'
import { useRoute } from 'vue-router'
import { useCountDown }  from '@/composables/useCountDown'
const { formatTime, start } = useCountDown()
const route = useRoute()
const orderDetail = ref([])
const getOrderDetail = async () => {
  const res = await getOrderDetailApi(route.query.id)
  orderDetail.value = res.result
  start(orderDetail.value.countdown)
}
onMounted(()=>getOrderDetail())
// 支付地址
const baseURL = 'http://pcapi-xiaotuxian-front-devtest.itheima.net/'
const backURL = 'http://localhost:5173/paycallback'
const redirectUrl = encodeURIComponent(backURL)
const payUrl = `${baseURL}pay/aliPay?orderId=${route.query.id}&redirect=${redirectUrl}`

</script>

<template>
  <div class="xtx-pay-page">
    <div class="container">
      <!-- 付款信息 -->
      <div class="pay-info">
        <span class="icon iconfont icon-queren2"></span>
        <div class="tip">
          <p>订单提交成功！请尽快完成支付。</p>
          <p>支付还剩 <span>{{ formatTime }}</span>, 超时后将取消订单</p>
        </div>
        <div class="amount">
          <span>应付总额：{{ orderDetail?.payMoney?.toFixed(2) }}</span>
          <span>¥</span>
        </div>
      </div>
      <!-- 付款方式 -->
      <div class="pay-type">
        <p class="head">选择以下支付方式付款</p>
        <div class="item">
          <p>支付平台</p>
          <a class="btn wx" href="javascript:;"></a>
          <a class="btn alipay" :href="payUrl"></a>
        </div>
        <div class="item">
          <p>支付方式</p>
          <a class="btn" href="javascript:;">招商银行</a>
          <a class="btn" href="javascript:;">工商银行</a>
          <a class="btn" href="javascript:;">建设银行</a>
          <a class="btn" href="javascript:;">农业银行</a>
          <a class="btn" href="javascript:;">交通银行</a>
        </div>
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
/* 支付页面主样式 */
.xtx-pay-page {
  padding: 20px 0;
  background-color: #f6f6f6;

  .container {
    max-width: 1200px;
    margin: 0 auto;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    padding: 30px;
  }

  /* 付款信息区域 */
  .pay-info {
    display: flex;
    align-items: center;
    padding: 20px;
    margin-bottom: 30px;
    background: #f8f8f8;
    border-radius: 4px;
    position: relative;

    &::after {
      content: "";
      position: absolute;
      left: 0;
      bottom: -15px;
      width: 100%;
      height: 1px;
      background: linear-gradient(90deg, transparent, #ddd, transparent);
    }

    .icon {
      font-size: 36px;
      color: #27ba9b;
      margin-right: 20px;
    }

    .tip {
      flex: 1;

      p {
        margin: 5px 0;

        &:first-child {
          font-size: 18px;
          font-weight: 500;
          color: #333;
        }

        &:last-child {
          font-size: 14px;
          color: #666;

          span {
            color: #cf4444;
            font-weight: bold;
          }
        }
      }
    }

    .amount {
      font-size: 20px;
      font-weight: bold;
      span:last-child {
        color: #cf4444;
        font-size: 24px;
      }
    }
  }

  /* 支付方式区域 */
  .pay-type {
    .head {
      font-size: 16px;
      font-weight: 500;
      padding-bottom: 10px;
      border-bottom: 1px solid #eee;
      margin-bottom: 20px;
    }

    .item {
      margin-bottom: 30px;

      p {
        font-size: 15px;
        color: #666;
        margin-bottom: 15px;
      }

      .btn {
        display: inline-block;
        width: 150px;
        height: 50px;
        line-height: 50px;
        text-align: center;
        margin-right: 15px;
        margin-bottom: 10px;
        border: 1px solid #e4e4e4;
        border-radius: 4px;
        background: #fff;
        color: #666;
        transition: all 0.3s;

        &:hover {
          border-color: #27ba9b;
          color: #27ba9b;
          background: #f0f9f7;
        }

        /* 支付平台图标样式 */
        &.wx {
          background: url(https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/c66f98cff8649bd5ba722c2e8067c6ca.jpg) no-repeat center / contain;
          background-size: contain;
        }

        &.alipay {
          background: url(https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/7b6b02396368c9314528c0bbd85a2e06.png) no-repeat center / contain;
          background-size: contain;
          cursor: pointer;
        }
      }
    }
  }

  /* 响应式调整 */
  @media (max-width: 768px) {
    padding: 10px;

    .container {
      padding: 15px;
    }

    .pay-info {
      flex-direction: column;
      text-align: center;
      padding: 15px;

      .icon {
        margin-right: 0;
        margin-bottom: 15px;
      }

      .amount {
        margin-top: 15px;
      }
    }

    .pay-type .item .btn {
      width: calc(50% - 10px);
      margin-right: 10px;
    }
  }
}
</style>
